﻿   MaskInput = function(f, m){	  
             								
               	   function mask(e){	
             	  	  var patterns = {'1': /[A-Z]/i, '2': /[0-9]/, '4': /[À-ÿ]/i, '8': /./ },	rules = { 'a': 3, 'A': 7, '9': 2, 'C':5, 'c': 1, '*': 8}; 
             		function accept(c, rule){  
             			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)	 
             				if(r & i && patterns[i].test(c))	 
             					break;	
             				return i <= r || c == rule;	   
             		}		  
             		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;	
             		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ? r[1] == 'O' ? r[0] : r[1] == 'E' ? !r[0] : accept(c, r[1]) || r[0]: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?	r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault(); 
             	}		  
             	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1}) 
             		addEvent(f, i, mask); 
             };	 

            function validar(str){
            var filter = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{1,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
            if(filter.test(str.value))
             str.style.borderColor='#00CC00';
             else{
             str.style.borderColor='#FF0000';
             }
            return false;
            };

            function ValidarCPF(Objcpf, e){        
            var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            var character = String.fromCharCode(code);
            var cpf = Objcpf.value + character;        
            exp = /\.|\-/g ;       
            cpf = cpf.toString().replace( exp, '' );         
            var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));        
            var soma1=0, soma2=0;        
            var vlr =11;                
            for(i=0;i<9;i++){                
            soma1+=eval(cpf.charAt(i)*(vlr-1));                
            soma2+=eval(cpf.charAt(i)*vlr);                
            vlr--;        
            }               
            soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));        
            soma2=(((soma2+(2*soma1))*10)%11);                
            var digitoGerado=(soma1*10)+soma2;        
            if(digitoGerado!=digitoDigitado)              
            Objcpf.style.borderColor='#FF0000';  
            else{
            Objcpf.style.borderColor='#00CC00';  
            } 
            return false;
            };

            function ValidarCNPJ(ObjCnpj, e){        
            var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            var character = String.fromCharCode(code);
            var cnpj = ObjCnpj.value + character;        
            var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);        
            var dig1= new Number;        
            var dig2= new Number;              
            exp = /\.|\-|\//g;        
            cnpj = cnpj.toString().replace( exp, '' );         
            var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));                        
            for(i = 0; i<valida.length; i++){                
            dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);            
            dig2 += cnpj.charAt(i)*valida[i];               
            }        
            dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));        
            dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));                
            if(((dig1*10)+dig2) != digito)                  
            ObjCnpj.style.borderColor='#FF0000';  
            else{
            ObjCnpj.style.borderColor='#00CC00';  
            } 
            return false;
            };

            function ValidaCep(cep, e){
            var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            var character = String.fromCharCode(code);
            exp = /\d{5}\-\d{3}/;
            if(!exp.test(cep.value + character))
            cep.style.borderColor='#FF0000';  
            else{
            cep.style.borderColor='#00CC00';  
            } 
            return false;
            };

            function ValidaTelefone(tel, e){   
            var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            var character = String.fromCharCode(code);
            exp = /\(\d{2}\)\ \d{4}\-\d{4}/;
            if(!exp.test(tel.value + character))
            tel.style.borderColor='#FF0000';  
            else{
            tel.style.borderColor='#00CC00';  
            } 
            return false;
            };

            function check_date(Data, e) {        
            var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;        
            var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            var character = String.fromCharCode(code);
            var DataAtual=Data.value + character;
            var vdt = new Date();        
            var vdia = vdt.getDay();        
            var vmes = vdt.getMonth();        
            var vano = vdt.getYear();
            if ((DataAtual.match(expReg)) && (DataAtual!='')){                
            var dia = DataAtual.substring(0,2);                
            var mes = DataAtual.substring(3,5);                
            var ano = DataAtual.substring(6,10);                
            if((mes==04 && dia > 30) || (mes==06 && dia > 30) || (mes==09 && dia > 30) || (mes==11 && dia > 30)){                        
            Data.style.borderColor='#FF0000';  
            } 
            else{ 
            if(ano%4!=0 && mes==2 && dia>28){                                        
            Data.style.borderColor='#FF0000';  
            } 
            else{
            if(ano%4==0 && mes==2 && dia>29){                                                                
            Data.style.borderColor='#FF0000';  
            } 
            else{
            if (ano > vano || ano < 1900) {                                                                                
            Data.style.borderColor='#FF0000';  
            }
            else{
            Data.style.borderColor='#00CC00';  
            }
            }
            }
            }
            } 
            else {
            Data.style.borderColor='#FF0000';  
            return false;   
            }
            };


            function limpavermelho(str){
             str.style.borderColor='#00CC00';
            return false;
            };